//
//  KKWishHomeViewController.m
//  WishFish
//
//  Created by liaozhenming on 2017/6/5.
//  Copyright © 2017年 liaozhenming. All rights reserved.
//

#import "KKWishHomeViewController.h"
#import "KKWishListViewController.h"

@interface KKWishHomeViewController ()

@property (nonatomic, strong) UIImageView *backgroundImageView;     /**<背景图片*/
@property (nonatomic, strong) UIView *shadowView;                   /**<阴影*/

@end

@implementation KKWishHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    {
        self.btn_send.layer.cornerRadius = 3.0;
        self.btn_send.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.btn_send.layer.borderWidth = 1.0;
        
        self.btn_record.layer.cornerRadius = 3.0;
        self.btn_record.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.btn_record.layer.borderWidth = 1.0;
    }
    
    {
        self.backgroundImageView = [[UIImageView alloc] initWithFrame: self.view.bounds];
        self.backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [self.view insertSubview: self.backgroundImageView atIndex:0];
        
        self.shadowView = [[UIView alloc] initWithFrame: self.view.bounds];
        self.shadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.shadowView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
        self.shadowView.alpha = CGFLOAT_MIN;
        [self.view insertSubview: self.shadowView atIndex:1];
        
        self.textBackgroundView.layer.cornerRadius = 5.0;
    }
    
    [self private_registerNotification];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Notification methods

- (void)private_registerNotification {
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(notication_keyboardChange:) name: UIKeyboardWillChangeFrameNotification object: nil];
}

- (void)notication_keyboardChange:(NSNotification*)notification {
    
    NSDictionary *userInfo = notification.userInfo;
    CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat pointY = CGRectGetMinY(endFrame);
    
    self.layout_bottomValue.constant = CGRectGetHeight([[UIScreen mainScreen] bounds]) - pointY;
    [self.view layoutIfNeeded];
}

#pragma mark - Action methods
- (IBAction)action_myWishFishList:(id)sender {
    //  我的许愿鱼
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName: @"Main" bundle:[NSBundle mainBundle]];
    KKWishListViewController *listViewController = [storyboard instantiateViewControllerWithIdentifier:@"KKWishListViewController"];
    [self.navigationController pushViewController: listViewController animated: true];
}

- (IBAction)action_createWishFish:(id)sender {
    //  扔一条许愿鱼
    self.functionView.hidden = YES;
}

- (IBAction)action_switch:(id)sender {
    
    self.btn_switch.selected = self.btn_switch.isSelected ? false : true;
    
    __weak typeof(self) weakSelf = self;
    if (self.btn_switch.isSelected) {
        self.btn_send.hidden = YES;
        self.btn_record.hidden = NO;
        
        [self.wishTextView resignFirstResponder];
        self.shadowView.alpha = 0.8;
        [UIView animateWithDuration:0.25 animations:^{
            weakSelf.textBackgroundView.alpha = CGFLOAT_MIN;
        } completion:^(BOOL finished) {
            weakSelf.textBackgroundView.hidden = YES;
        }];
    }
    else {
        self.btn_send.hidden = NO;
        self.btn_record.hidden = YES;
        
        self.textBackgroundView.hidden = NO;
        weakSelf.textBackgroundView.alpha = CGFLOAT_MIN;
        weakSelf.shadowView.alpha = CGFLOAT_MIN;
        [UIView animateWithDuration:0.25 animations:^{
            weakSelf.textBackgroundView.alpha = 1.0;
            weakSelf.shadowView.alpha = 1.0;
        } completion:^(BOOL finished) {
            [weakSelf.wishTextView becomeFirstResponder];
        }];
    }
}

- (IBAction)action_startRecord:(id)sender {
    
}

- (IBAction)action_stopRecord:(id)sender {
    
}

@end
